package com.zsxb.crm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zsxb.crm.dto.SystemLogPageDTO;
import com.zsxb.crm.mapper.SystemLogMapper;
import com.zsxb.crm.pojo.TbSystemLog;
import com.zsxb.crm.result.PageResult;
import com.zsxb.crm.service.SystemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemLogServiceImpl implements SystemLogService {
    @Autowired
    private SystemLogMapper systemLogMapper;

    @Override
    public PageResult pageQuery(SystemLogPageDTO systemLogPageDTO) {
        PageHelper.startPage(systemLogPageDTO.getPageNum(), systemLogPageDTO.getPageSize());
        //处理数据
        if (systemLogPageDTO.getParams()!=null){
            String beginTime = systemLogPageDTO.getParams().get("beginTime").toString();
            systemLogPageDTO.setBeginTime(beginTime);
            String endTime =  systemLogPageDTO.getParams().get("endTime").toString();
            systemLogPageDTO.setEndTime(endTime);
        }
        Page<TbSystemLog> logList = (Page<TbSystemLog>) systemLogMapper.pageQuery(systemLogPageDTO);
        PageResult pageResult = new PageResult();
        pageResult.setTotal(logList.getTotal());
        pageResult.setRows(logList.getResult());
        return pageResult;
    }

    @Override
    public void delete(List<Integer> ids) {
        if (ids == null){
            return;
        }
        systemLogMapper.delete(ids);
    }
}
